package digital_cash_system.customer;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

import digital_cash_system.Logger;
import digital_cash_system.XJFrame;

public class CustomerGUI extends XJFrame implements ActionListener
{
	private static final long serialVersionUID = 1L;

	private final static String openAccountButtonTitle = "Open account";
	private final static String withdrawButtonTitle = "Withdraw";
	private final static String payButtonTitle = "Pay";

	private JButton openAccountButton;
	private JButton withdrawButton;
	private JButton payButton;

	Customer customer = new Customer();

	public CustomerGUI()
	{
		super("Klient");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		setSize(850, 600);
		setLocation(100, 100);
		setResizable(false);
		setLayout(null);

		// --- setup menu
		int buttonYPosition = ButtonsMenuYPosition;

		openAccountButton = new JButton(openAccountButtonTitle);
		openAccountButton.setBounds(ButtonsMenuXPosition, buttonYPosition, 200, 50);
		add(openAccountButton);
		openAccountButton.addActionListener(this);

		buttonYPosition += ButtonsPadding;
		withdrawButton = new JButton(withdrawButtonTitle);
		withdrawButton.setBounds(ButtonsMenuXPosition, buttonYPosition, 200, 50);
		add(withdrawButton);
		withdrawButton.addActionListener(this);

		buttonYPosition += ButtonsPadding;
		payButton = new JButton(payButtonTitle);
		payButton.setBounds(ButtonsMenuXPosition, buttonYPosition, 200, 50);
		add(payButton);
		payButton.addActionListener(this);
		// ---

		loggerView.setBounds(300, 10, 500, 500);
		loggerView.setEditable(false);
		add(loggerView);

		setVisible(true);
	}

	public static void main(String[] args)
	{
		new CustomerGUI();
	}

	@Override
	public void actionPerformed(ActionEvent e)
	{
		Object source = e.getSource();

		if (source == openAccountButton)
		{
			// --- logger output
			Logger.getInstance().write("Open account");
			// ---
			customer.openAccount();
		} else if (source == withdrawButton)
		{
			// --- logger output
			Logger.getInstance().write("Withdraw");
			// ---
			customer.withdrawCoin();
		} else if (source == payButton)
		{
			// --- logger output
			Logger.getInstance().write("Pay");
			// ---
			customer.pay();
		}

	}
}
